using System.Web.UI;

namespace octalforty.Syndication.uF.UI
{
    /// <summary>
    /// Creates a representation of the <c>hCard</c> microformat.
    /// </summary>
    public class HCard : MicroformatWebControl
    {
        #region Private Member Variables
        private uF.HCard card = new uF.HCard();
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets or sets a reference to the <see cref="uF.HCard"/> to
        /// be displayed.
        /// </summary>
        public uF.HCard Card
        {
            get { return card; }
            set { card = value; }
        }
        #endregion

        /// <summary>
        /// Initializes a new instance of <see cref="HCard"/> class.
        /// </summary>
        public HCard()
        {
        }

		#region WebControl Members
		/// <summary>
		/// Sends server control content to a provided <see cref="System.Web.UI.HtmlTextWriter"/>  object, which 
		/// writes the content to be rendered on the client. 
		/// </summary>
		/// <param name="writer"></param>
    	protected override void Render(HtmlTextWriter writer)
    	{
			if(Card == null)
				return;

			//
			// VCard root span
			writer.AddAttribute(HtmlTextWriterAttribute.Class, "vcard");
			if(Hidden)
				writer.AddAttribute("style", "display: none;");

			writer.RenderBeginTag(HtmlTextWriterTag.Span);
            
			//
			// FN, Email and ORG tags
            RenderMicroformatTag(writer, HtmlTextWriterTag.Span, "fn", Card.FullName);
            RenderMicroformatTag(writer, HtmlTextWriterTag.Span, "email", Card.EmailAddress);
            RenderMicroformatTag(writer, HtmlTextWriterTag.Span, "org", Card.OrganizationalName);

            writer.RenderEndTag();
    	}
    	#endregion
    }
}
